<!DOCTYPE html>
<html lang="en" class="no-js" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorator="layout">
<head>
<title>会员管理</title>
 <script th:inline="javascript">
/*<![CDATA[*/
           
jQuery.validator.addMethod("checkPassWord2", function(value, element) { 
	var password = $("#inputPassword").val();
	var id = $("#id").val();
	if(id!="" && password==""){
		return true;
	}
	return value!="" ;  
	}, "请输入确认密码");
	
jQuery.validator.addMethod("checkPassword", function(value, element) { 
	var password = $("#inputPassword").val();
	var id = $("#id").val();
	return this.optional(element) || value==password ;  
	}, "密码不一致，请重新输入");
	
jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
	}, "请正确填写您的手机号码");

$().ready(function() {
	$("#userForm").validate({
              rules:{
            	  email:{
            		  email:true
            	  },
            	  password2:{
            		  checkPassWord2:true,
            		  checkPassword:true
                  },
                  mobile:{
                	  isMobile:true
                  }
              },
              messages:{
            	  email:{
            		  email:"请输入正确格式的电子邮件"
            	  }
              }		
	});
});
	
/*]]>*/
</script>
</head>
<body>
<div layout:fragment="content">
	<div class="row">
		<div class="col-md-12">
			<div class="btn-group pull-right">
				<a href="index.html" th:href="@{/user/list/}" id="sample_editable_1_new" class="btn green">返回<i class="fa fa-arrow-circle-o-left"></i></a>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="form">
				<form role="form" th:action="@{/user/save}" th:object="${user}" id="userForm" method="post" class="form-horizontal">
					<h4 class="form-section">会员信息</h4>
					<input type="hidden" th:field="*{id}" />
					<div class="form-body">
						<div class="form-group" th:class="${#fields.hasErrors('name')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">会员名<span class="required" aria-required="true">* </span></label>							
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="会员名" th:field="*{name}" required=""/>
								<span class="help-block" th:if="${#fields.hasErrors('name')}" th:errors="*{name}">用户名称不能为空</span>
							</div>
						</div>
						<div class="form-group" th:class="${#fields.hasErrors('email')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">邮箱<span class="required" aria-required="true">* </span></label>							
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="邮箱" th:field="*{email}"/>
								<span class="help-block" th:if="${#fields.hasErrors('email')}" th:errors="*{email}">邮箱不能为空</span>
							</div>
						</div>
						<div class="form-group" th:class="${#fields.hasErrors('password')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">登录密码<span class="required" aria-required="true">* </span></label>							
							<div class="col-md-4">
								<input type="password" class="form-control" placeholder="登录密码" name="inputPassword" id="inputPassword"/>
								<span class="help-block" th:if="${#fields.hasErrors('password')}" th:errors="*{password}">邮箱不能为空</span>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">确认密码<span class="required" aria-required="true">* </span></label>
							<div class="col-md-4">
								<input type="password" class="form-control" placeholder="确认密码" id="password2" name="password2" />
								<span class="help-block"></span>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">会员等级</label>
							<div class="col-md-4">
								<select th:field="*{userRank}" th:remove="all-but-first" class="form-control">
					                <option th:each="type : ${userRanks}"
					                        th:value="${type.id}" th:text="${type.rankName}"></option>
					            </select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">性别</label>
							<div class="col-md-4">
					            <label class="radio-inline"><span><input type="radio" name="userSex"  id="optionsRadios4" value="0" checked="" th:field="*{userSex}" /></span> 保密</label>
					            <label class="radio-inline"><span><input type="radio" name="userSex"  id="optionsRadios4" value="1" checked="" th:field="*{userSex}" /></span> 男</label>
					            <label class="radio-inline"><span><input type="radio" name="userSex"  id="optionsRadios4" value="2" checked="" th:field="*{userSex}" /></span> 女</label>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">等级积分</label>
							<div class="col-md-4">
								<span th:text="*{levelPoint}"></span> [ <a th:if="${user.id} != null" href="#" th:href="@{'/userlog/index/'+${user.id}}"  class="btn default btn-xs purple" name="Link_userlogEdit">查看明细</a> <span th:unless="${user.id} != null">查看明细</span> ] 
								<span class="help-block"></span>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">消费积分</label>
							<div class="col-md-4">
								<span th:text="*{consumePoint}"></span> [ <a th:if="${user.id} != null" href="#" th:href="@{'/userlog/index/'+${user.id}}"  class="btn default btn-xs purple" name="Link_userlogEdit">查看明细</a> <span th:unless="${user.id} != null">查看明细</span> ] 
								<span class="help-block"></span>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-3">生日</label>
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="生日" th:field="*{userBirthday}" />
								<span class="help-block"></span>
							</div>
						</div>
						<div class="form-group" th:class="${#fields.hasErrors('mobile')}? 'form-group has-error' : 'form-group'">
							<label class="control-label col-md-3">手机号<span class="required" aria-required="true">* </span></label>
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="手机号" th:field="*{mobile}" />
								<span class="help-block" th:if="${#fields.hasErrors('mobile')}" th:errors="*{mobile}">手机号不能为空</span>
							</div>
						</div>	
					</div>
					<div class="form-group">
						<label class="control-label col-md-3">会员状态</label>
						<div class="col-md-9">
							<div class="radio-list">
								<label class="radio-inline"
									th:each="eachValue : ${userStatus}"> <span><input
										th:field="*{status}" type="radio" name="status"
										th:value="${eachValue}" th:text="${eachValue.description}"/></span></label>
							</div>
						</div>
					</div>
					<div class="form-actions fluid">
						<div class="col-md-offset-3 col-md-9">
							<button type="submit" class="btn blue" name="sub">提交</button>
						</div>
					</div>
				</form>		
			</div>
		</div>
	</div>
</div>	
</body>
</html>